home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / misc / football / exec / league.rexx < prev    next >
OS/2 REXX Batch file  |  1999-02-03  |  13KB  |  379 lines

  1. /* ***********************************************************************
  2.  
  3.    LEAGUE PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------
  5.                    Copyright  Mark Naughton 1996
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       090996   First release.
  11.            090996   As the sort doesnt flip the negative numbers, was
  12.                     thought to be a problem, the league is checked and
  13.                     flipped correctly (LEAGUE2.REXX)
  14.            120996   Amended same code as it didn't work if the two 'signs'
  15.                     were different. Now flips them correctly.
  16.                     (LEAGUE2.REXX)
  17.            180996   Changed record-count so that it is stored in element
  18.                     zero of each array. Deleted some variable assigns
  19.                     that weren't needed. Amended reading into arrays so
  20.                     that the count is set correctly for one element.
  21.                     Removed all "call "references before library routines.
  22.            180996   Removed all "call " references, used element zero to
  23.                     store the record-count. (LEAGUE2.REXX)
  24.            260996   Amended program so that the sortprogram and the REXX
  25.                     program to display the league are called from here
  26.                     instead of a separate script file. Changed so that the
  27.                     count is not stored in 'zero' element.
  28.            270996   Added code for points_per_draw and points_per_loss.
  29.                     Updated to use new filenames. Improved error messages.
  30.                     Inserted code from LEAGUE2.REXX to speed things up and
  31.                     to tidy the code. Finally got the table to be sorted
  32.                     properly, using a version of VSORTA from asd_library.
  33.  1.1       111196   Added argument so it can become a component of
  34.                     FOOTBALL. Removed GAMEPLAY and EXTRACT. Removed all
  35.                     messages.
  36.            131196   Added checks for files - if not found, exits without
  37.                     a message.
  38.            141196   Added code to highlight the leader.
  39.            201196   Added code to sort out which teams are relegated and
  40.                     then to display the line at the correct place.
  41.            211196   Updated and tidied the display.
  42.            231296   Shortened lines when displaying the league.
  43.            241296   Tidied up display again.
  44.  1.2       110497   Added code to support Points_Per_Goals. Amended the
  45.                     table display.
  46.            070597   Amended code that checks league_file to see if they
  47.                     are in the right order - was using wrong parameters.
  48.            080597   Amended as FOOTSORT is only used for league table file
  49.                     sorting.
  50.  2.0       240997   Tidied up code and added errors in case any files cannot
  51.                     be read or written to. Simplified reading of teams and
  52.                     data (getting it from '.df' now, not '.stats') and
  53.                     getting the total teams without having to re-read the
  54.                     '.stats' file. Added promotion bar.
  55.            151297   Tidied display.
  56.  
  57. **************************************************************************
  58.  
  59. Procedure
  60. ---------
  61.  
  62. 1. Check files exist. Open 'Teams.df'.
  63. 2. Read in teams and their associated data; WIN, DRAW, LOST etc.
  64. 3. Close file. Open 'Teams.stats'. Read data. Close file.
  65. 4. Open 'Teams.sf' for reading.
  66. 5. Read each line that has a game played, and from that get the team names
  67.    and the score. Then update the relevant team data with the result.
  68. 6. Write data in form of a league table to an output file.
  69. 7. Close file.
  70. 8. Call external sortprogram to sort the output file.
  71. 9. Open 'Teams.stats' and read the number of teams, then close.
  72. 10.Open 'League.output' and read contents into two arrays.
  73. 11.Check to see if the teams are in the right order, comparing the points
  74.    of each one with the next and if the goal-differences are in the wrong
  75.    order, then swap the two teams.
  76. 12.Check to see which teams are relegated by calculating the maximum number
  77.    of points available and seeing if the lower teams are able to move up.
  78.    If not they are relegated, according to the number set.
  79. 13.Check to see which teams are promoted by using the same method as above.
  80. 14.Display league and exit.
  81.  
  82. ************************************************************************** */
  83. ARG league_file
  84.  
  85. version      = 2
  86. league_file  = "Data/" || league_file
  87. input_file   = '.stats'
  88. input2_file  = '.sf'
  89. input3_file  = '.df'
  90. output_file  = 'Data/League.output'
  91. title        = '*LEAGUE_NAME='
  92. points_win   = '*POINTS_PER_WIN='
  93. points_drw   = '*POINTS_PER_DRW='
  94. points_lse   = '*POINTS_PER_LSE='
  95. points_gls   = '*POINTS_PER_GLS='
  96. releg        = '*RELEGATION='
  97. playother    = '*PLAY_OTHER='
  98. promoted     = '*PROMOTED='
  99. team_counter = '*COUNTR='
  100. team         = '*TEAM='
  101. played       = '*PLY='
  102. won          = '*WIN='
  103. drawn        = '*DRW='
  104. lost         = '*LST='
  105. goalsf       = '*GOF='
  106. goalsa       = '*GOA='
  107. points       = '*PTS='
  108. separator    = '*'
  109. teams.       = '???'
  110. teams2.      = '???'
  111. m_ply.       = '???'
  112. m_win.       = '???'
  113. m_drw.       = '???'
  114. m_lost.      = '???'
  115. m_gof.       = '???'
  116. m_goa.       = '???'
  117. m_pts.       = '???'
  118. teams_ctr    = 0
  119. playo        = 2
  120. reg          = 2
  121. ptsgls       = 0
  122. ptswin       = 2
  123. ptsdrw       = 1
  124. ptslse       = 0
  125. promo        = 0
  126. not_played   = '__   __'
  127.  
  128.  
  129. if exists(league_file || input_file) = 0  then exit
  130. if exists(league_file || input2_file) = 0 then exit
  131. if exists(league_file || input3_file) = 0 then exit
  132.  
  133.  
  134. tcount = 0
  135. if open(datafile,league_file || input3_file,'r') then do
  136.    do while ~eof(datafile)
  137.       line = readln(datafile)
  138.       if pos(title,line) > 0 then        league_title = delstr(line,1,13)
  139.       if pos(points_win,line) > 0 then   ptswin=delstr(line,1,16)
  140.       if pos(points_drw,line) > 0 then   ptsdrw=delstr(line,1,16)
  141.       if pos(points_lse,line) > 0 then   ptslse=delstr(line,1,16)
  142.       if pos(points_gls,line) > 0 then   ptsgls=delstr(line,1,16)
  143.       if pos(releg,line) > 0 then        reg = delstr(line,1,12)
  144.       if pos(playother,line) > 0 then    playo = delstr(line,1,12)
  145.       if pos(promoted,line) > 0 then     promo = delstr(line,1,10)
  146.       if pos(separator,line) = 0 then do
  147.          line = strip(line)
  148.          tcount       = tcount + 1
  149.          teams.tcount = line
  150.       end
  151.    end
  152.    close(datafile)
  153. end
  154. else do
  155.    say
  156.    say "ERROR :    (League)"
  157.    say
  158.    say "Unable to open '"league_file || input3_file"' file."
  159.    exit
  160. end
  161.  
  162. if open(datafile,league_file || input_file,'r') then do
  163.    do while ~eof(datafile)
  164.       line = readln(datafile)
  165.       if pos(team,line) > 0 then
  166.          teams_ctr = teams_ctr + 1
  167.       if pos(played,line) > 0 then  m_ply.teams_ctr  = delstr(line,1,5)
  168.       if pos(won,line) > 0 then     m_won.teams_ctr  = delstr(line,1,5)
  169.       if pos(drawn,line) > 0 then   m_drw.teams_ctr  = delstr(line,1,5)
  170.       if pos(lost,line) > 0 then    m_lost.teams_ctr = delstr(line,1,5)
  171.       if pos(goalsf,line) > 0 then  m_gof.teams_ctr  = delstr(line,1,5)
  172.       if pos(goalsa,line) > 0 then  m_goa.teams_ctr  = delstr(line,1,5)
  173.       if pos(points,line) > 0 then  m_pts.teams_ctr  = delstr(line,1,5)
  174.    end
  175.    close(datafile)
  176. end
  177. else do
  178.    say
  179.    say "ERROR :    (League)"
  180.    say
  181.    say "Unable to open '"league_file || input_file"'."
  182.    exit
  183. end
  184.  
  185. if open(datafile,league_file || input2_file,'r') then do
  186.    do while ~eof(datafile)
  187.       line = readln(datafile)
  188.       if pos(separator,line) = 0 then do
  189.          if pos(not_played,line) = 0 then do
  190.             home_team = strip(substr(line,1,30))
  191.             goals_for = substr(line,32,2)
  192.             goals_aga = substr(line,37,2)
  193.             away_team = strip(substr(line,41,30))
  194.  
  195.             do i=1 to teams_ctr
  196.                if home_team = teams.i then do
  197.                   m_ply.i = m_ply.i + 1
  198.                   m_gof.i = m_gof.i + goals_for
  199.                   m_goa.i = m_goa.i + goals_aga
  200.                   if goals_for = goals_aga then do
  201.                      m_drw.i = m_drw.i + 1
  202.                      m_pts.i = m_pts.i + ptsdrw
  203.                   end
  204.                   if goals_for < goals_aga then do
  205.                      m_lost.i= m_lost.i + 1
  206.                      m_pts.i = m_pts.i + ptslse
  207.                   end
  208.                   if goals_for > goals_aga then do
  209.                      m_won.i = m_won.i + 1
  210.                      m_pts.i = m_pts.i + ptswin
  211.                   end
  212.                   m_pts.i = m_pts.i + (goals_for * ptsgls)
  213.                end
  214.             end
  215.             do i=1 to teams_ctr
  216.                if away_team = teams.i then do
  217.                   m_ply.i = m_ply.i + 1
  218.                   m_gof.i = m_gof.i + goals_aga
  219.                   m_goa.i = m_goa.i + goals_for
  220.                   if goals_for = goals_aga then do
  221.                      m_drw.i = m_drw.i + 1
  222.                      m_pts.i = m_pts.i + ptsdrw
  223.                   end
  224.                   if goals_for < goals_aga then do
  225.                      m_won.i = m_won.i + 1
  226.                      m_pts.i = m_pts.i + ptswin
  227.                   end
  228.                   if goals_for > goals_aga then do
  229.                      m_lost.i= m_lost.i + 1
  230.                      m_pts.i = m_pts.i + ptslse
  231.                   end
  232.                   m_pts.i = m_pts.i + (goals_aga * ptsgls)
  233.                end
  234.             end
  235.          end
  236.       end
  237.    end
  238.    close(datafile)
  239. end
  240. else do
  241.    say
  242.    say "ERROR :    (League)"
  243.    say
  244.    say "Unable to open '"league_file || input2_file"'."
  245.    exit
  246. end
  247.  
  248. if open(outfile,output_file,"w") then do
  249.    do i=1 to teams_ctr
  250.       line = teams.i
  251.       line = insert(" ",line,length(line)+1,30-length(line))
  252.       mp = right(m_ply.i,3)
  253.       mw = right(m_won.i,3)
  254.       md = right(m_drw.i,3)
  255.       ml = right(m_lost.i,3)
  256.       mgf = right(m_gof.i,5)
  257.       mga = right(m_goa.i,5)
  258.       mpts = right(m_pts.i,7)
  259.       writech(outfile,line"   "mp" "mw" "md" "ml" "mgf" "mga"  "mpts"      ")
  260.       itemp=mgf-mga
  261.       if itemp>0 then
  262.          itemp=insert("+",itemp,0,1)
  263.       itemp=right(itemp,4)
  264.       writeln(outfile,itemp)
  265.    end
  266.    close(outfile)
  267. end
  268. else do
  269.    say
  270.    say "ERROR :    (League)"
  271.    say
  272.    say "Unable to update the League. Cannot write to '"output_file"'."
  273.    exit
  274. end
  275.  
  276. address command 'Exec/footsort '
  277.  
  278. if open(datafile2,output_file,'r') then do
  279.    do i=1 to tcount
  280.       line = readln(datafile2)
  281.       teams.i  = line
  282.       teams2.i = line
  283.    end
  284.    close(datafile2)
  285. end
  286. else do
  287.    say
  288.    say "ERROR :    (League)"
  289.    say
  290.    say "Cannot read '"output_file"'."
  291.    exit
  292. end
  293.  
  294. ctr = 0
  295. do while swapctr > 0
  296.    swapctr=9
  297.    do i=1 to tcount-1                               /* was 64,4 and 77,4 */
  298.       swapdone=0
  299.       j = i + 1
  300.       if strip(substr(teams.i,64,7)) = strip(substr(teams.j,64,7)) then do
  301.          goaldiffa = strip(substr(teams.i,77,5))
  302.          goaldiffb = strip(substr(teams.j,77,5))
  303.          if goaldiffa < goaldiffb then do
  304.             teams.i = teams2.j
  305.             teams.j = teams2.i
  306.             teams2.i= teams.i
  307.             teams2.j= teams.j
  308.             swapdone= 1
  309.             ctr = ctr + 1
  310.          end
  311.       end
  312.       if swapdone = 1 then
  313.          break
  314.    end
  315.    if ctr = 0 then
  316.       swapctr = 0
  317.    else
  318.       ctr = 0
  319. end
  320.  
  321. if reg > 0 then do             /* this bit of code checks to see which teams are relegated */
  322.    posreg   = 0
  323.    wherereg = tcount - reg
  324.    regpts   = strip(substr(teams.wherereg,64,7))         /* was 64,4 */
  325.    do i=tcount to 1 by -1
  326.       b = (((tcount-1) * playo) - strip(substr(teams.i,36,2))) * ptswin
  327.       c = strip(substr(teams.i,64,7)) + b
  328.       if c < regpts then posreg = i                 /* calculates the max points avail */
  329.    end
  330.    if posreg > (wherereg+1) then posreg = wherereg + 1     /* was 0 - set to reqd pos if higher */
  331. end
  332.  
  333. /* ---------------------------------------------- */
  334.  
  335.  
  336. if promo > 0 then do          /* this bit of code checks to see which teams are promoted */
  337.    pospro   = 0
  338.    wherepro = promo + 1
  339.    propts   = strip(substr(teams.wherepro,64,7))         /* was 64,4 */
  340.    do i=1 to tcount
  341.       b = (((tcount-1) * playo) - strip(substr(teams.i,36,2))) * ptswin
  342.       c = strip(substr(teams.i,64,7)) + b
  343.       if c > propts then pospro = i                 /* calculates the max points avail */
  344.    end
  345.    if pospro < (wherepro-1) then pospro = wherepro - 1     /* was 0 - set to reqd pos if higher */
  346. end
  347.  
  348.  
  349. /* ---------------------------------------------- */
  350.  
  351. say
  352. say center(league_title,88)
  353. say "-----------------------------------------------------------------------------------------"
  354. say
  355. say
  356. say "    Team                               Pl Won Drw Lst GoalsF GoalsA    Pts     GoalDiff"
  357. say "-----------------------------------------------------------------------------------------"
  358.  
  359. do i=1 to tcount
  360.    if strip(substr(teams.i,76,5)) = 0 then teams.i=overlay("",teams.i,76,5," ")
  361.    if i<10 then do
  362.       if i = 1 then teams.i = upper(teams.i)
  363.       say " "i") "teams.i
  364.    end
  365.    else
  366.       say i") "teams.i
  367.    if i + 1 = posreg & reg > 0 then do
  368.       say "_________________________________________________________________________________________"
  369.       say
  370.    end
  371.    if i = pospro & promo > 0 then do
  372.       say "_________________________________________________________________________________________"
  373.       say
  374.    end
  375. end
  376. say "-----------------------------------------------------------------------------------------"
  377. say
  378.  
  379. exit